package com.jgp.workflow.service;

import com.jgp.sys.query.Operator;
import com.jgp.sys.query.QueryFilterList;
import com.jgp.workflow.model.ImportantTask;
import com.jgp.workflow.repository.ImportantTaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2020-06-16
 */
@Service
public class ImportantTaskService {
    
    @Autowired
    private ImportantTaskRepository repository;
    
    @Transactional
    public void addImportant(String taskId){
        QueryFilterList filters = new QueryFilterList();
        filters.addFilter("taskId", Operator.eq,taskId);
        ImportantTask task = repository.readOne(filters);
        if(Objects.isNull(task)){
            ImportantTask importantTask = new ImportantTask();
            importantTask.setTaskId(taskId);
            repository.create(importantTask);
        }
    }
    
    @Transactional
    public void removeImportant(String taskId){
        QueryFilterList filters = new QueryFilterList();
        filters.addFilter("taskId",Operator.eq,taskId);
        repository.delete(filters);
    }
    
    @Transactional
    public void addImportantForProc(String procId){
        QueryFilterList filters = new QueryFilterList();
        filters.addFilter("procId",Operator.eq,procId);
        ImportantTask task = repository.readOne(filters);
        if(Objects.isNull(task)){
            ImportantTask importantTask = new ImportantTask();
            importantTask.setProcId(procId);
            repository.create(importantTask);
        }
    }
    
    @Transactional
    public void removeImportantForProc(String procId){
        QueryFilterList filters = new QueryFilterList();
        filters.addFilter("procId",Operator.eq,procId);
        repository.delete(filters);
    }
}
